/*
 * SwingEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import java.util.EventObject;

import com.cute4j.swing.Component;
import com.cute4j.util.CommonConstants;

/**
 * Swing Event.
 *
 * @cute4j.native
 *    generate="header"
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class SwingEvent extends EventObject {

// Public Static Fields. -------------------------------------------------------

  /**
   * The component event mask.
   */
  public static final long COMPONENT_EVENT_MASK = 0x00001;

  /**
   * The key event mask.
   */
  public static final long FOCUS_EVENT_MASK = 0x00004;

  /**
   * The key event mask.
   */
  public static final long KEY_EVENT_MASK = 0x00008;

 /**
  * The mouse event mask.
  */
  public static final long MOUSE_EVENT_MASK = 0x00010;

  /**
   * The mouse motion event mask.
   */
  public static final long MOUSE_MOTION_EVENT_MASK = 0x00020;

  /**
   * The window event mask.
   */
  public static final long WINDOW_EVENT_MASK = 0x00040;

  /**
   * The action event mask.
   */
  public static final long ACTION_EVENT_MASK = 0x00080;

  /**
   * The paint event mask.
   */
  public static final long PAINT_EVENT_MASK = 0x02000;

  /**
   * The mouse wheel event mask.
   */
  public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;

  /**
   * The mouse wheel event mask.
   */
  public static final long LOCATION_TOOL_TIP_MASK = 0x400000;

  /**
   * The context event mask.
   */
  public static final long CONTEXT_MENU_EVENT_MASK = 0x100000;

  /**
   * The custom context event mask.
   */
  public static final long CUSTOM_CONTEXT_MENU_EVENT_MASK = 0x200000;

  /**
   * The paint view event mask.
   */
  public static final long PAINT_VIEW_EVENT_MASK = 0x400000;

// Private Fields. -------------------------------------------------------------

  private static final long serialVersionUID = -295417051659006329L;

// Protected Fields. -----------------------------------------------------------

  protected int id;
  protected boolean consumed;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new SwingEvent object.
   *
   * @param source the source of the event
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public SwingEvent(Object source) {
    super(source);
  }

  /**
   * Constructs new SwingEvent object.
   *
   * @param source the source of the event
   * @param id the event type
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public SwingEvent(Object source, int id) {
    super(source);
    this.id = id;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the event type.
   *
   * @return the event type
   */
  public int getID() {
    return id;
  }

  /**
   * Returns string representation of the event.
   *
   * @return string representation of the event
   */
  public String paramString() {
    return CommonConstants.STRING_EMPTY;
  }

// Protected Methods. ----------------------------------------------------------

  /**
   * Returns <tt>true</tt> if the event is consumed.
   *
   * @return <tt>true</tt> if the event is consumed
   */
  protected boolean isConsumed() {
    return consumed;
  }

  /**
   * Consumes the event.
   */
  protected void consume() {
    consumed = true;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String toString() {
    String sourceName = null;
    if (source instanceof Component) {
      sourceName = ((Component)source).getName();
    }
    if ((sourceName == null) && (source != null)) {
      sourceName = source.toString();
    }
    return getClass().getName() + "[" + paramString() + "] on " + sourceName;
  }

}
